import request from '@/utils/request'

export const departmentApi = {
  // 获取部门树
  getDepartmentTree() {
    return request({
      url: '/api/departments/tree',
      method: 'get'
    })
  },

  // 获取部门列表
  getDepartments(params) {
    return request({
      url: '/api/departments',
      method: 'get',
      params
    })
  },

  // 获取部门详情
  getDepartment(id) {
    return request({
      url: `/api/departments/${id}`,
      method: 'get'
    })
  },

  // 创建部门
  createDepartment(data) {
    return request({
      url: '/api/departments',
      method: 'post',
      data
    })
  },

  // 更新部门
  updateDepartment(id, data) {
    return request({
      url: `/api/departments/${id}`,
      method: 'put',
      data
    })
  },

  // 删除部门
  deleteDepartment(id) {
    return request({
      url: `/api/departments/${id}`,
      method: 'delete'
    })
  },

  // 更新排序
  updateOrder(data) {
    return request({
      url: '/api/departments/order',
      method: 'put',
      data
    })
  },

  // 获取权限模板列表
  getTemplates() {
    return request({
      url: '/api/departments/templates',
      method: 'get'
    })
  },

  // 获取预分配的部门编码
  generateCode(parentId) {
    return request({
      url: '/api/departments/generate-code',
      method: 'get',
      params: { parent_id: parentId }
    })
  }
}

export default departmentApi 